<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">

            <h:form id="userForm" enctype="multipart/form-data">
                 <br/>
                <h3 class="title">Atualizando Requerimento</h3>
                
                <p:growl id="messages" showDetail="true" autoUpdate="true"  /> 
                <div class="row">
                    <div class="twelve columns"> 
                       <fieldset>
                            <legend> <h4 style="margin:0 0 10px 0">Entrada</h4></legend>
                            <p:panel id="reqPanel" style="background: none; border: none;" 
                                     styleClass="container_24 clearfix both">

                                <p:outputLabel value="Processo:" styleClass="grid_3" for="processInputText"/>
                                <p:inputText id="processInputText" styleClass="grid_8" 
                                             value="#{managerSearchRequirement.editReq.process}" />

                                <p:outputLabel value="Tipo:" styleClass="grid_3" for="typeRequirementSelectOneMenu"/>
                                <div class="grid_8">
                                    <p:selectOneMenu id="typeRequirementSelectOneMenu" required="true" 
                                                     requiredMessage="O tipo de Requerimento é Obrigatório" 
                                                     value="#{managerSearchRequirement.editReq.type_requeriment}">
                                        <f:selectItem itemLabel="" itemValue=""/>
                                        <f:selectItems value="#{managerSearchRequirement.typeRequeriment}"/>  
                                        <p:ajax event="change"  update=":userForm:docPanel "
                                                listener="#{managerSearchRequirement.ajaxTypeAnnex()}" />
                                    </p:selectOneMenu>
                                </div>
                                <div class="clear" /> 
                            </p:panel>

                        </fieldset>

                        <fieldset> 
                            <legend> <h4 style="margin:0 0 10px 0">Interessado</h4></legend>
                            <p:panel id="qualidadePanel" style="background: none; border: none;" 
                                     styleClass="container_24 clearfix both "> 

                                <p:outputLabel value="Nome:" styleClass="grid_3" for="interestedInputText"/>
                                <p:inputText id="interestedInputText" styleClass="grid_20 ajustInput" 
                                             value="#{managerSearchRequirement.editReq.interested}" />
                                <p:outputLabel value="CPF:" styleClass="grid_3" for="cpfInterestedInputMask"/>
                                <p:inputMask id="cpfInterestedInputMask" mask="999.999.999-99" styleClass="grid_8" 
                                             value="#{managerSearchRequirement.editReq.cpfInterested}" />
                                <p:outputLabel value="Qualidade:" styleClass="grid_3" for="typeQualitySelectOneMenu"/>
                                <div class="grid_8" >
                                    <p:selectOneMenu id="typeQualitySelectOneMenu" required="true" 
                                                     requiredMessage="O tipo de Qualidade é Obrigatório" 
                                                     value="#{managerSearchRequirement.editReq.typeQuality}">
                                        <f:selectItem itemLabel="" itemValue=""/>
                                        <f:selectItems value="#{managerSearchRequirement.typeQuality}"/>  

                                    </p:selectOneMenu>
                                </div>
                                <div class="clear" /> 

                                <fieldset>  
                                    <legend> <h4 style="margin:0 0 10px 0">Endereço</h4></legend>
                                    <p:outputLabel value="Rua:" styleClass="grid_3" for="addressInterestedInputText"/>
                                    <p:inputText id="addressInterestedInputText" styleClass="grid_20 ajustInput" 
                                                 value="#{managerSearchRequirement.editReq.addressInterested}" />
                                    
                                    <p:outputLabel value="Bairro:" styleClass="grid_3" for="neighborhoodInterestedInputText"/>
                                    <p:inputText id="neighborhoodInterestedInputText" styleClass="grid_8" 
                                                 value="#{managerSearchRequirement.editReq.neighborhoodInterested}" />
                                    <p:outputLabel value="CEP:" styleClass="grid_2" for="zipCodeNeighborhoodInterestedInputMask"/>
                                    <p:inputMask id="zipCodeNeighborhoodInterestedInputMask" mask="99.999-999" styleClass="grid_4" 
                                                 value="#{managerSearchRequirement.editReq.zipCodeNeighborhoodInterested}" />
                                    <p:outputLabel value="Nº:" styleClass="grid_2 alpha" for="numInterestedInputText"/>
                                    <p:inputText id="numInterestedInputText" styleClass="grid_3" 
                                                 value="#{managerSearchRequirement.editReq.numInterested}" />

                                </fieldset>

                            </p:panel>

                        </fieldset>
                        <fieldset>
                            <legend> <h4 style="margin:0 0 10px 0">Situação</h4></legend>
                            <p:panel id="sitPanel" style="background: none; border: none;" >            
                                <p:selectOneRadio styleClass="situation" value="#{managerSearchRequirement.editReq.status}">
                                    <f:selectItems value="#{managerSearchRequirement.status}"/>   
                                </p:selectOneRadio>
                            </p:panel>
                        </fieldset>
                        <fieldset>
                            <legend> <h4 style="margin:0 0 10px 0">Proprietário</h4></legend>
                            <p:panel id="intPanel" style="background: none; border: none;" 
                                     styleClass="container_24 clearfix both ">
 
                                <p:panel id="typePeoplePanel" 
                                         style="background: none; border: none; margin-left: -7px; margin-top: -20px;" 
                                         styleClass="container_24 clearfix both ">
                                    <p:outputLabel value="Pessoa:"  styleClass="grid_3" for="typePerson"/>
                                    <p:selectOneRadio id="typePerson" style="margin-top:-8px;" styleClass="grid_8"
                                                    value="#{managerSearchRequirement.interested.typeDocument}" >  
                                        <f:selectItems value="#{managerSearchRequirement.typeDocumentList()}" />
                                        <p:ajax event="change" update=":userForm:intPanel" />
                                    </p:selectOneRadio>

                                    <div class="clear"/>
                                </p:panel>

                                <div class="clear"/>

                                <p:outputLabel id="typeDocumentLabel" for="typeDocumentInput"
                                                value="#{managerSearchRequirement.interested.typeDocument}: " 
                                                styleClass="grid_3"/>

                                <p:inputMask id="typeDocumentInput" 
                                                value="#{managerSearchRequirement.interested.typeDocument.type eq 'CPF' ? 
                                                        managerSearchRequirement.interested.cpf : managerSearchRequirement.interested.cnpj}"
                                                mask="#{managerSearchRequirement.interested.typeDocument.type eq 'CPF' ? 
                                                        '999.999.999-99':'99.999.999/9999-99'}" 
                                                styleClass="grid_8" > 
                                    <p:ajax event="blur" update=":userForm:intPanel" 
                                            listener="#{managerSearchRequirement.existInterested()}" />
                                </p:inputMask>
                                <div class="clear"/>
                                <p:outputLabel value="Nome:" styleClass="grid_3" for="nomeInputText" 
                                                rendered="#{managerSearchRequirement.interested.typeDocument.type eq 'CPF'}"/>
                                <p:inputText id="nomeInputText" styleClass="grid_20 ajustInput"  
                                                value="#{managerSearchRequirement.interested.name}" 
                                                readonly="#{managerSearchRequirement.readOnlyInputs}"
                                                rendered="#{managerSearchRequirement.interested.typeDocument.type eq 'CPF'}" />

                                <p:outputLabel value="Fantasia:" styleClass="grid_3"
                                                for="nameFantasyInputText" 
                                                rendered="#{managerSearchRequirement.interested.typeDocument.type eq 'CNPJ'}" />
                                <p:inputText id="nameFantasyInputText" styleClass="grid_20 ajustInput"
                                                readonly="#{managerSearchRequirement.readOnlyInputs}"
                                                value="#{managerSearchRequirement.interested.name_fantasy}" 
                                                rendered="#{managerSearchRequirement.interested.typeDocument.type eq 'CNPJ'}" />

                            </p:panel>
                        </fieldset>
                        <fieldset>
                            <legend> <h4 style="margin:0 0 10px 0">Imóvel</h4></legend>
                            <p:panel id="imoPanel" style="background: none; border: none;" 
                                     styleClass="container_24 clearfix ">

                                <p:outputLabel value="CEP:" styleClass="grid_3" for="cepReqInputMask"/>
                                <p:inputMask id="cepReqInputMask" mask="99.999-999"  styleClass="grid_4"
                                              value="#{managerSearchRequirement.editReq.zipCodeNeighborhood}" />
                                <div class="clear-both" />

                                <p:outputLabel value="Logradouro:" styleClass="grid_3" for="addressInputText"/>
                                <p:inputText id="addressInputText" styleClass="grid_20 ajustInput"
                                             value="#{managerSearchRequirement.editReq.addressImovel}" />

                                <p:outputLabel value="Bairro:" styleClass="grid_3" for="districtInputText"/>
                                <p:inputText id="districtInputText" styleClass="grid_20 ajustInput"
                                              value="#{managerSearchRequirement.editReq.neighborhoodImovel}" />

                                <p:outputLabel value="Número:" styleClass="grid_3" for="numberInputText"/>
                                <p:inputText id="numberInputText" styleClass="grid_4" 
                                             value="#{managerSearchRequirement.editReq.numberImovel}" />
                                
                                <p:outputLabel value="Fone:" styleClass="grid_3 phoneLabel" for="phoneReqInputMask"/>
                                <p:inputMask id="phoneReqInputMask" mask="(99) 9999-9999" styleClass="grid_5"
                                             value="#{managerSearchRequirement.editReq.foneImovel}" />
                                <div class="clear-both" />

                                <p:outputLabel value="Obs:" styleClass="grid_3" for="psInputTextarea"/>
                                <p:inputTextarea id="psInputTextarea" styleClass="grid_20 ajustInput"
                                                 value="#{managerSearchRequirement.editReq.obs}" />

                            </p:panel>

                        </fieldset>
                         <fieldset>
                            <legend> <h4 style="margin:0 0 10px 0">Documentos</h4></legend>
                            <p:panel id="docPanel" style="background: none; border: none;" 
                                     styleClass="container_24 clearfix ">

                                <p:outputLabel value="Documento:" styleClass="grid_3" for="doc"/>
                                <div class="grid_19">
                                    <p:selectOneMenu id="doc" value="#{managerSearchRequirement.annex.type_annex}">
                                        <f:selectItem itemLabel="" itemValue=""/>
                                        <f:selectItems id="docItens" value="#{managerSearchRequirement.typeAnnex}"/>   
                                        <p:ajax event="change" process="docPanel" update="docPanel" 
                                                listener="#{managerSearchRequirement.ajaxTypeAnnex()}"/>
                                    </p:selectOneMenu>
                                </div>
                                <div class="clear"/>
                                <br/>
                                <p:fileUpload 
                                    mode="advanced"
                                    label="Anexar"
                                    fileUploadListener="#{managerSearchRequirement.handle}"
                                    multiple="true"
                                    auto="true" disabled="#{managerSearchRequirement.disableAnnexButton}"
                                    invalidFileMessage="Tipo de arquivo não suportado."
                                    invalidSizeMessage="Tamanho do arquivo não é suportado"
                                    uploadLabel="Enviar"
                                    cancelLabel="Cancelar"
                                    immediate="true"
                                    update="messages, tableAnnex, docItens"
                                    />
                                <div class="clear"/>
                                <br/>

                                <p:dataGrid id="tableAnnex" var="a" value="#{managerSearchRequirement.annexs}" 
                                            rowIndexVar="rowid"
                                            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                            rows="6" paginator="true"  
                                            paginatorPosition="bottom"
                                            emptyMessage="Nenhum registro">  
                                 
                                    <p:panel header="#{a.type_annex.name}" style="text-align:center; width: 280px;">  

                                        <h:outputLink  
                                            value="#{a.type ne 'application/pdf' ? 'viewImage.xhtml':'show'}" title="#{a.description}"  target="_blank" >

                                            <div style="text-align: center; width: 20%;" class="grid_4">

                                                <p:graphicImage styleClass="image grid_3" rendered="#{a.type ne 'application/pdf'}"
                                                                style="margin-left:1%; width: 50px;"
                                                                url="show/?annex=#{a.id}" />

                                                <p:outputLabel  value="#{a.description.length() ge 10 ? a.description.substring(0, 10).concat('...') : 
                                                                         a.description.replace('.png','').replace(' ','_')}" 
                                                                style="margin-left:1%; width: 100px;" rendered="#{a.type ne 'application/pdf'}"/>

                                                <p:graphicImage styleClass="image grid_3" rendered="#{a.type eq 'application/pdf'}"
                                                                style="margin-left:1%; width: 100px;" 
                                                                url="assets/images/pdf.jpeg" />


                                                <p:outputLabel  value="#{a.description.length() ge 10 ? a.description.substring(0, 10).concat('...') : 
                                                                         a.description.replace('.pdf','').replace(' ','_')}" 
                                                                style="margin-left:1%; width: 100px;" rendered="#{a.type eq 'application/pdf'}"/>

                                            </div>
                                            <f:param name="annex" value="#{a.id}"/>
                                            <p:commandButton  style="width: 30px; height: 30px; float: right" 
                                                              title="remover" update="@form"
                                                              actionListener="#{managerSearchRequirement.removeAnnex(rowid)}"
                                                              icon="ui-icon-trash"/>
                                        </h:outputLink>
                                        <div class="clear"/>

                                    </p:panel>  

                                  
                                </p:dataGrid>   
                            </p:panel>

                        </fieldset>

<!--                        <fieldset>
                            <legend> <h4 style="margin:0 0 10px 0">Documentos</h4></legend>
                            <p:panel id="docPanel" style="background: none; border: none;" 
                                     styleClass="container_24 clearfix ">

                                <p:outputLabel value="Documento: " styleClass="grid_3" for="documentSelectOneMenu"/>
                                <div class="grid_19 ">
                                    <p:selectOneMenu id="documentSelectOneMenu" panelStyle="width: 150px"
                                                    value="{managerSearchRequirement.annex.type_annex}">
                                        <f:selectItem itemLabel="" itemValue=""/>
                                        <f:selectItems id="docItens" value="{managerSearchRequirement.typeAnnex}"/>   
                                        <p:ajax event="change" process="docPanel" update="docPanel" listener="{managerSearchRequirement.ajaxTypeAnnex()}"/>
                                    </p:selectOneMenu>
                                </div>
                                <div class="clear"/>
                                
                                <br/>
                                <p:fileUpload 
                                    mode="advanced"
                                    label="Anexar"
                                    fileUploadListener="{managerSearchRequirement.handle}"
                                    multiple="true"
                                    auto="true" disabled="{managerSearchRequirement.disableAnnexButton}"
                                    invalidFileMessage="Tipo de arquivo não suportado."
                                    invalidSizeMessage="Tamanho do arquivo não é suportado"
                                    uploadLabel="Enviar"
                                    cancelLabel="Cancelar"
                                    immediate="true"
                                    update="messages, tableAnnex, documentSelectOneMenu, docItens"
                                    />
                                <div class="clear"/>

                            </p:panel>

                            <p:panel id="docPanelAnnex" style="background: none; border: none;" 
                                     styleClass="container_24 clearfix ">
                                <p:dataTable id="tableAnnex" var="a" value="{managerSearchRequirement.annexs}" 
                                             styleClass="grid_24"
                                             rowIndexVar="rowid"
                                             rowKey="{a.id}"
                                             rows="5" paginator="true"  
                                             paginatorPosition="bottom"
                                             emptyMessage="Nenhum registro">  
                                                                        <f:facet name="header">
                                                                            Documentos 
                                                                        </f:facet>
                                    <p:column headerText="Tipo Documento" width="400">  
                                        <h:outputText value="{a.type_annex.name}" style="font-weight: bold"/>
                                       
                                    </p:column> 
                                    <p:column headerText="Digital" width="400">  
                                        <h:outputLink  
                                            value="{a.type ne 'application/pdf' ? 'viewImage.xhtml':'show'}" title="{a.description}"  target="_blank" >

                                            <div style="text-align: center; width: 20%;" class="grid_4">

                                                <p:graphicImage styleClass="image grid_3" rendered="{a.type ne 'application/pdf'}"
                                                                style="margin-left:1%; width: 50px;"
                                                                url="show/?annex={a.id}" />

                                                <p:outputLabel  value="{a.description.length() ge 10 ? a.description.substring(0, 10).concat('...') : 
                                                                        a.description.replace('.png','').replace(' ','_')}" 
                                                                style="margin-left:1%; width: 100px;" rendered="{a.type ne 'application/pdf'}"/>

                                                <p:graphicImage styleClass="image grid_3" rendered="{a.type eq 'application/pdf'}"
                                                                style="margin-left:1%; width: 100px;" 
                                                                url="assets/images/pdf.jpeg" />


                                                <p:outputLabel  value="{a.description.length() ge 10 ? a.description.substring(0, 10).concat('...') : 
                                                                        a.description.replace('.pdf','').replace(' ','_')}" 
                                                                style="margin-left:1%; width: 100px;" rendered="{a.type eq 'application/pdf'}"/>
                                            </div>
                                            <f:param name="annex" value="{a.id}"/>
                                        </h:outputLink>

                                    </p:column> 
                                    <p:column headerText="Ação" width="30">
                                        <p:commandButton  style="width: 30px; height: 30px;" 
                                                          title="remover" update="@form"
                                                          actionListener="{managerSearchRequirement.removeAnnex(rowid)}"
                                                          icon="ui-icon-trash"/>
                                    </p:column>
                                </p:dataTable>     
                            </p:panel>
                        </fieldset>-->

                        <br/>
                        <div class="buttonAction">
                            <p:commandButton value="Atualizar" icon="ui-icon-disk"
                                             update="@form"
                                             actionListener="#{managerSearchRequirement.updateRequeriment()}"
                                             styleClass="ui-priority-primary" />
                            <p:button href="searchreq.xhtml" value="Voltar"  icon="ui-icon-arrowreturnthick-1-w" />
                        </div >
                    </div>
                </div>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
